package com.tedu.sp06;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
//@EnableCircuitBreaker

@SpringCloudApplication
public class Sp07RibbonApplication {

	public static void main(String[] args) {
		SpringApplication.run(Sp07RibbonApplication.class, args);
	}
  //创建RestTemplate实例，并将它放入spring容器
    @LoadBalanced
	@Bean
	public RestTemplate getRestTemplate(){
	   SimpleClientHttpRequestFactory f=new SimpleClientHttpRequestFactory();
	  //两个超时参数默认是-1，表示不启动超时，只要不响应就一直等
	   f.setConnectTimeout(1000);//设置超时时间为1s.会等待1s
	   f.setReadTimeout(1000);//等待响应的超时时间
		return new RestTemplate(f);
   }

}
